/**
 * Created by dbwyxl on 2017/9/11.
 */
module.exports =function($http,httpservice,$q){
  var caseSourcesService={
    getServiceType:getServiceType,
    getServiceList:getServiceList,
    getBusinessType:getBusinessType,
    getServiceDetail:getServiceDetail,
    takeService:takeService,
    servicecaseFileDownload:servicecaseFileDownload
  };
  return caseSourcesService;


  //获取左侧列表
  function getServiceType() {
    var deferred = $q.defer();
    $http({
      method: 'POST',
      url: httpservice.getServiceTypeUrl,
      params: '',
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  }

  //案源列表
  function getServiceList(params){
    var deferred = $q.defer();
    $http({
      method: 'POST',
      url: httpservice.getServiceListUrl,
      data:params,
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  }
  //筛选列表
  function getBusinessType(){
    return $http({
      method: 'POST',
      url: httpservice.getBusinessTypeUrl,
      data:{}
    })
  }
  //接单详情
  function getServiceDetail(id,serviceid){
    var deferred = $q.defer();
    var params={
      id:id,
      serviceid:serviceid
    };
    $http({
      method: 'POST',
      url: httpservice.getServiceDetailUrl,
      data:params,
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  }
  //确认接单
  function takeService(id){
    var deferred = $q.defer();
    var params={
      id:id
    };
    $http({
      method: 'POST',
      url: httpservice.takeServiceUrl,
      data:params,
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  }
  //下载附件
  function servicecaseFileDownload (id){
    var deferred = $q.defer();
    var params={
      caseSourceId:id
    };
    $http({
      method: 'POST',
      url: httpservice.servicecaseFileDownloadUrl,
      data:params,
      responseType: 'arraybuffer',
      headers: {'Content-Type': 'application/json'}
    }).then(function successCallback(response) {
      deferred.resolve(response.data);
    }, function errorCallback(response) {
      deferred.reject(response);
    });
    return deferred.promise;
  }
};
